package com.fourpigeon.dao;

import com.fourpigeon.domain.BlogAgree;
import com.fourpigeon.domain.BlogDeal;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 约球贴
 * 数据库操作
 */
@Mapper
@Repository
public interface BlogAgreeDao {
    @Select("select * from tb_blog_junior where userId = #{userId} and id<#{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogAgree> getJuniorByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_advanced where userId = #{userId} and id<#{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogAgree> getAdvancedByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_senior where userId = #{userId} and id<#{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogAgree> getSeniorByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_junior where id = #{id} and status < 2")
    public BlogAgree getByJuniorId(Long id);
    @Select("select * from tb_blog_advanced where id = #{id} and status < 2")
    public BlogAgree getByAdvancedId(Long id);
    @Select("select * from tb_blog_senior where id = #{id} and status < 2")
    public BlogAgree getBySeniorId(Long id);

    @Select("select * from tb_blog_junior where status<2")
    public List<BlogAgree> getAllJunior();
    @Select("select * from tb_blog_advanced where status<2")
    public List<BlogAgree> getAllAdvanced();
    @Select("select * from tb_blog_senior where status<2")
    public List<BlogAgree> getAllSenior();


    @Update("update tb_blog_junior set name=#{name},time=#{time},location=#{location},type=#{type},curpeople=#{curpeople},people=#{people},contact=#{contact},content=#{content},status=#{status} where id = #{id}")
    public boolean updateJunior(BlogAgree blogDeal);
    @Update("update tb_blog_advanced set name=#{name},time=#{time},location=#{location},type=#{type},curpeople=#{curpeople},people=#{people},contact=#{contact},content=#{content},status=#{status} where id = #{id}")
    public boolean updateAdvanced(BlogAgree blogDeal);
    @Update("update tb_blog_senior set name=#{name},time=#{time},location=#{location},type=#{type},curpeople=#{curpeople},people=#{people},contact=#{contact},content=#{content},status=#{status} where id = #{id}")
    public boolean updateSenior(BlogAgree blogDeal);


    @Insert("insert into tb_blog_junior values(#{id},#{userId},#{userName},#{icon},#{name},#{time},#{location},#{type},#{curpeople},#{people},#{contact},#{content},#{status},#{createTime},#{updateTime})")
    public boolean saveJunior(BlogAgree blogDeal);
    @Insert("insert into tb_blog_advanced values(#{id},#{userId},#{userName},#{icon},#{name},#{time},#{location},#{type},#{curpeople},#{people},#{contact},#{content},#{status},#{createTime},#{updateTime})")
    public boolean saveAdvanced(BlogAgree blogDeal);
    @Insert("insert into tb_blog_senior values(#{id},#{userId},#{userName},#{icon},#{name},#{time},#{location},#{type},#{curpeople},#{people},#{contact},#{content},#{status},#{createTime},#{updateTime})")
    public boolean saveSenior(BlogAgree blogDeal);


    @Delete("delete from tb_blog_junior where id = #{id}")
    public boolean deleteJunior(Long id);
    @Delete("delete from tb_blog_advanced where id = #{id}")
    public boolean deleteAdvanced(Long id);
    @Delete("delete from tb_blog_senior where id = #{id}")
    public boolean deleteSenior(Long id);

    @Select("select * from tb_blog_junior where id < #{start} and status < 2 order by createTime DESC,id DESC limit 6")
    public List<BlogAgree> getJuniors(Long start);
    @Select("select * from tb_blog_advanced where id < #{start} and status < 2 order by createTime DESC,id DESC limit 6")
    public List<BlogAgree> getAdvanceds(Long start);
    @Select("select * from tb_blog_senior where id < #{start} and status < 2 order by createTime DESC,id DESC limit 6")
    public List<BlogAgree> getSeniors(Long start);

    @Select("select * from tb_blog_junior where (name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%')) and type = #{type} and status < 2")
    public List<BlogAgree> getSearchJuniors(String searchKeyWord, Short type);

    @Select("select * from tb_blog_advanced where (name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%')) and type = #{type} and status < 2")
    public List<BlogAgree> getSearchAdvances(String searchKeyWord, Short type);

    @Select("select * from tb_blog_senior where (name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%')) and type = #{type} and status < 2")
    public List<BlogAgree> getSearchSeniors(String searchKeyWord, Short type);

    @Select("select * from tb_blog_junior where name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') and status < 2")
    public List<BlogAgree> getAllSearchJuniors(String searchKeyWord);

    @Select("select * from tb_blog_advanced where name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') and status < 2")
    public List<BlogAgree> getAllSearchAdvances(String searchKeyWord);

    @Select("select * from tb_blog_senior where name like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') and status < 2")
    public List<BlogAgree> getAllSearchSeniors(String searchKeyWord);

    @Select("select * from tb_blog_junior where type = #{type} and status < 2")
    public List<BlogAgree> getJuniorsByType(Short type);

    @Select("select * from tb_blog_advanced where type = #{type} and status < 2")
    public List<BlogAgree> getAdvancesByType(Short type);

    @Select("select * from tb_blog_senior where type = #{type} and status < 2")
    public List<BlogAgree> getSeniorsByType(Short type);

    @Update("update tb_blog_advanced set status = 1 where id = #{id}")
    public boolean reportBlogA(Long id);

    @Update("update tb_blog_senior set status = 1 where id = #{id}")
    public boolean reportBlogS(Long id);

    @Update("update tb_blog_junior set status = 1 where id = #{id}")
    public boolean reportBlogJ(Long id);
}
